const IndexModel = require("../../model/home/indexModel.js")
class Index {
	/**
	 * @param {Object} ctx
	 * @description 获取首页 菜单接口
	 */
	static async getMenu(ctx) {
		let res = await IndexModel.getMenu()
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}

	/**
	 * @description 获取首页轮播图
	 * @param {Object} ctx
	 * @param {String} keyword 关键字
	 */
	static async getAdList(ctx) {
		let res = await IndexModel.getad()
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}

	// 获取商品列表
	static async getGoodsList(ctx) {
		let { city, nowpage, pagesize } = ctx.request.query
		let res = await IndexModel.getGoods(city, nowpage, pagesize)
		console.log(res, 35)
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}
	// 获取视频列表
	static async getVideoList(ctx) {
		let { nowpage, pagesize } = ctx.request.query
		let res = await IndexModel.getVideo(nowpage, pagesize)
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}

	static async getVideoUser(ctx) {
		const { vid, uid } = ctx.query
		let res = await IndexModel.getVideoUser(vid, uid)
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}
	// 获取商品详情
	static async getGoodsDetail(ctx) {
		let { id } = ctx.request.query
		let res = await IndexModel.getGoodsDetail(id)
		if (res) {
			ctx.body = {
				code: 0,
				codeInfo: "成功",
				data: res
			}
		} else {
			ctx.body = {
				code: 1,
				codeInfo: "该商品已经下架"
			}
		}
	}

	static async searchGoods(ctx) {
		let { nowpage, pagesize, keyword } = ctx.request.query
		console.log({ nowpage, pagesize, keyword }, 62)
		let res = await IndexModel.searchGoods(nowpage, pagesize, keyword)
		ctx.body = {
			code: 0,
			codeInfo: "成功",
			data: res
		}
	}

	static async clickBtn(ctx) {
		const { type, uid, vid, vuser } = ctx.query
		if (!type || !uid || !vid || !vuser) {
			ctx.body = { code: 1, codeInfo: "参数不足" }
		} else {
			await IndexModel.videoEdit(type, uid, vid, vuser)
			ctx.body = { code: 0, codeInfo: '操作成功！' }
		}

	}


}
module.exports = Index